package cn.itsource.dd.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.dd.domain.Detail;
import cn.itsource.dd.domain.Type;
import cn.itsource.dd.mapper.DetailMapper;
import cn.itsource.dd.mapper.TypeMapper;
import cn.itsource.dd.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class TypeServiceImpl extends BaseServiceImpl<Type> implements ITypeService {
    @Autowired
    private TypeMapper typeMapper;
    @Autowired
    private DetailMapper detailMapper;
    @Override
    @Transactional
    public void save(Type type){
        if(type.getId()==null){
            //添加
            typeMapper.save(type);
        }
            //修改
        typeMapper.update(type);
    }
    @Override
    public void delete(Long id){
        //根据数据字典id先删除明细表
        detailMapper.deleteByTypeId(id);
        //删除数据字典
        typeMapper.delete(id);
    }
}
